home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utildsk / memry374.lha / memory-device / source / speed.c < prev   
C/C++ Source or Header  |  1996-03-29  |  3KB  |  149 lines

  1. /*
  2. ** $VER: speed.c 1.0 (23 Mar 1996)
  3. **
  4. ** (C) Copyright 1996 Marius Gröger
  5. **     All Rights Reserved
  6. **
  7. ** $HISTORY:
  8. **
  9. ** 23 Mar 1996 : 001.000 :  created
  10. */
  11.  
  12. #define DEBUG 0
  13.  
  14. /*F*/ /* includes */
  15. #ifndef CLIB_ALIB_PROTOS_H
  16. #include <clib/alib_protos.h>
  17. #endif
  18. #ifndef CLIB_EXEC_PROTOS_H
  19. #include <clib/exec_protos.h>
  20. #include <pragmas/exec_sysbase_pragmas.h>
  21. #endif
  22. #ifndef CLIB_DOS_PROTOS_H
  23. #include <clib/dos_protos.h>
  24. #include <pragmas/dos_pragmas.h>
  25. #endif
  26.  
  27. #ifndef EXEC_MEMORY_H
  28. #include <exec/memory.h>
  29. #endif
  30.  
  31. #ifndef DOS_DOS_H
  32. #include <dos/dos.h>
  33. #endif
  34.  
  35. #ifndef __DEBUG_H
  36. #include "debug.h"
  37. #endif
  38. #ifndef __COMPILER_H
  39. #include "compiler.h"
  40. #endif
  41. /*E*/
  42. /*F*/ /* imports */
  43. IMPORT ASM VOID CopyMemWarp(REG(a0) VOID *src, REG(a1) VOID *dst, REG(d0) ULONG len);
  44. IMPORT VOID exit(LONG);
  45. IMPORT struct Library *DOSBase, *SysBase;
  46. /*E*/
  47.  
  48. #define DEF_SIZE 512
  49. #define DEF_NUMBER 1000
  50.  
  51. /*F*/ STATIC ULONG systime(VOID)
  52. {
  53.    struct DateStamp ds;
  54.  
  55.    DateStamp(&ds);
  56.  
  57.    return (ULONG)(ds.ds_Days*24*60*60*TICKS_PER_SECOND +
  58.                   ds.ds_Minute*60*TICKS_PER_SECOND +
  59.                   ds.ds_Tick);
  60. }
  61. /*E*/
  62. /*F*/ STATIC VOID usage(UBYTE *name)
  63. {
  64.    Printf(
  65.       "Usage: %s [options]\n"                                  \
  66.       "Options: -n <num>      Copy <num> number of blocks\n"   \
  67.       "         -s <size>     Set blocksize to <size>*512\n"
  68.    , name);
  69. }
  70. /*E*/
  71. /*F*/ VOID SAVEDS STDARGS main(ULONG argc, UBYTE **argv)
  72. {
  73.    LONG i;
  74.    LONG rc = RETURN_OK;
  75.    LONG number = DEF_NUMBER, size = DEF_SIZE;
  76.  
  77.    for (i=1; i<argc; i++)
  78.    {
  79.       UBYTE *arg = argv[i];
  80.  
  81.       if (*arg++ == '-')
  82.       {
  83.          switch(*arg++)
  84.          {
  85.             case 'n':
  86.                if (!StrToLong(arg, &number) || number <= 0)
  87.                {
  88.                   usage(argv[0]);
  89.                   rc = RETURN_FAIL;
  90.                }
  91.             break;
  92.  
  93.             case 's':
  94.                if (!StrToLong(arg, &size) || size <= 0)
  95.                {
  96.                   usage(argv[0]);
  97.                   rc = RETURN_FAIL;
  98.                }
  99.                size *= 512;
  100.             break;
  101.  
  102.             default:
  103.                Printf("Unknown option '%lc'\n",arg[-1]);
  104.                usage(argv[0]);
  105.                rc = RETURN_FAIL;
  106.          }
  107.       }
  108.       else
  109.       {
  110.          usage(argv[0]);
  111.          rc = RETURN_FAIL;
  112.       }
  113.    }
  114.  
  115.    if (rc == RETURN_OK)
  116.    {
  117.       UBYTE *p1, *p2;
  118.       ULONG before, after;
  119.  
  120.       p1 = AllocVec(size, MEMF_ANY);
  121.       p2 = AllocVec(size, MEMF_ANY);
  122.  
  123.       Printf("Performing %ld times CopyMemWarp(0x%08lx, 0x%08lx, %ld)...",
  124.                                                      number, p1, p2, size);
  125.       Flush(Output());
  126.  
  127.       if (p1 && p2)
  128.       {
  129.          Forbid();
  130.          before = systime();
  131.          for (i = 0; i<number; i++)
  132.             CopyMemWarp(p1, p2, size);
  133.          after = systime();
  134.          Permit();
  135.          after -= before;
  136.       }
  137.  
  138.       Printf("ready.\nOperation needed %ld seconds and %ld ticks\n",
  139.             after / TICKS_PER_SECOND, after % TICKS_PER_SECOND);
  140.  
  141.       if (p1) FreeVec(p1);
  142.       if (p2) FreeVec(p2);
  143.    }
  144.  
  145.    exit(rc);
  146. }
  147. /*E*/
  148.  
  149.